# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/22 下午2:32
 @Author  : tgy
 
"""
import re

text = '2012-12-21,xxx'
text01 = 'abc'

compile = re.compile(r'\d{4}-\d{1,2}-\d{1,2}')

text02 = "zhangsan,age=21,gender=man,Age=22,AGE=23"

def test01():

    # print(compile.search(text01).group())
    res = compile.search(text01)
    if res:
        print(res.group())
    print(compile.match(text).group())


def test_sub():
    ...

    sub_compile = re.compile(r'(\d+)')
    # 要使用 \1,\2,\3，必须使用分组，\1是第一个分组，\2是第二个分组，以此类推
    print(sub_compile.sub(r'aa\1bb', text02))


def call_back(text):
    def inner(re):
        ...
        print(re)
        return text
    return inner

def test_replace_igon():
    ...
    sub_compile = re.compile(r'age',re.IGNORECASE)
    print(sub_compile.sub(lambda r:r'old', text02))



if __name__ == '__main__':
    ...
    # test01()
    # test_sub()
    test_replace_igon()